package com.baizhi.service.impl;

import org.apache.ibatis.session.SqlSession;

import com.baizhi.dao.QuestionDao;
import com.baizhi.entity.Question;
import com.baizhi.service.QuestionService;
import com.baizhi.util.MyBatisUtils;

import java.util.List;

public class QuestionServiceImpl implements QuestionService {

	@Override
	public void insert(Question question) {
		SqlSession sqlSession = null;
		try {
			sqlSession = MyBatisUtils.getSqlSession();
			QuestionDao qd=sqlSession.getMapper(QuestionDao.class);
			qd.insert(question);
			sqlSession.commit();
		} catch (Exception e) {
			e.printStackTrace();
			sqlSession.rollback();
		}finally{
			MyBatisUtils.close(sqlSession);
		}
	}

	@Override
	public List<Question> selectByPageId(int pageId) {
		SqlSession sqlSession = null;
		List<Question> quesList=null;
		try {
			sqlSession = MyBatisUtils.getSqlSession();
			QuestionDao qd=sqlSession.getMapper(QuestionDao.class);
			quesList = qd.selectByPageId(pageId);
			sqlSession.commit();
		} catch (Exception e) {
			e.printStackTrace();
			sqlSession.rollback();
		}finally{
			MyBatisUtils.close(sqlSession);
		}
		return quesList;
	}

}
